<?php
namespace app\common\model;

class FilmModel extends \think\Model
{
    protected $table = 'db_film';

    protected $autoWriteTimestamp = 'datetime';

    // 定义时间戳字段名
    protected $createTime = 'c_time';
    protected $updateTime = 'u_time';


    /**
     * 电影删除的标识
     */
    CONST STATUS_DEL = -1;

    /**
     * 电影发布的标识
     */
    CONST STATUS_NORMAL = 1;


    public function getTagsAttr() {
        $tagRelations = FilmTagRelationModel::where('film_id', '=', $this->id)->select();

        $tags = [];
        foreach ($tagRelations as $tagRelation) {
            $tags[] = [
                'id' => $tagRelation->tag_id,
                'tag' => $tagRelation->tag_name
            ];
        }

        return $tags;
    }



    public function getSiteNameAttr() {
        $site = FilmSiteModel::cache(true)->get($this->site_id);
        return $site->site_name;
    }
}
